<?php

/**
 * This is the model class for table "tbl_contactForm".
 *
 * The followings are the available columns in table 'tbl_contactForm':
 * @property integer $id
 * @property string $name
 * @property string $email
 * @property string $phonenumber
 * @property string $subject
 * @property string $body
 * @property string $service_type
 * @property string $fee
 * @property string $offer_date
 * @property string $starting_date
 * @property string $verifyCode
 */
class ContactForm extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return ContactForm the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'tbl_contactForm';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('name, email, phonenumber, subject, body, service_type, verifyCode', 'required'),

			array('name, phonenumber, verifyCode', 'length', 'max'=>128),
			array('email, subject,fee', 'length', 'max'=>255),
                        array('email','email'),
			array('fee', 'length', 'max'=>20),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, name, email, phonenumber, subject,service_type, fee', 'safe', 'on'=>'search'),
                      array('verifyCode', 'captcha', 'allowEmpty'=>!CCaptcha::checkRequirements()),
                    array('verifyCode', 'captcha', 'allowEmpty'=>!extension_loaded('gd')),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	  public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'name' => 'Tên',
			'email' => 'Email',
			'phonenumber' => 'Số Điện Thoại',
			'subject' => 'Chủ Đề',
			'body' => 'Nội Dung',
			'service_type' => 'Dịch Vụ Yêu Cầu',
                        'offer_date' => 'Ngày Yêu Cầu Dịch Vụ',
                        'starting_date' => 'Ngày Bắt Đầu Dịch Vụ',
			'fee' => 'Chi Phí Ước Tính',
                        'verifyCode'=>'Mã Xác Nhận',
		);
	}
	

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('name',$this->name,true);
		$criteria->compare('email',$this->email,true);
		$criteria->compare('phonenumber',$this->phonenumber,true);
		$criteria->compare('subject',$this->subject,true);
		$criteria->compare('body',$this->body,true);
		$criteria->compare('service_type',$this->service_type);
		$criteria->compare('fee',$this->fee,true);
		$criteria->compare('verifyCode',$this->verifyCode,true);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
}